package com.czx.decorator.impl;

import com.czx.decorator.CommonCacheService;
import com.czx.util.RedisUtils;
import org.aspectj.lang.ProceedingJoinPoint;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class RedisCacheServiceImpl implements CommonCacheService {

    @Autowired
    private RedisUtils redisUtils;

    @Autowired
    private JvmCacheServiceImpl jvmCacheServiceImpl;

    @Override
    public <T> T get(String key, Class<T> T, ProceedingJoinPoint proceedingJoinPoint) {
        T t = redisUtils.getEntity(key, T);
        if (t != null) {
            return t;
        }
        t = jvmCacheServiceImpl.get(key, T, proceedingJoinPoint);
        if (t != null) {
            redisUtils.putEntity(key, t);
            return t;
        }
        return null;
    }
}
